# -*- coding:utf-8 -*-
# @Author : mistchan
# @Time : 2021/4/24 0024 20:27
# @File : main.py
# @Software: PyCharm

from PIL import Image
import glob
import datetime


def file_name():
    return datetime.datetime.now().strftime('%Y%m%d-%H%M%S-%f')


def join_image():
    bg = Image.new('RGB', (3508, 2479), (255, 255, 255))
    idx = 1

    for i, each in enumerate(glob.glob('.\\放入所有待拼接图片\\*')):
        im_open = Image.open(each)
        x, y = im_open.size
        height = int(750 / x * y)
        im_resize = im_open.resize((750, height), Image.ANTIALIAS)
        bg.paste(im_resize, (100 * idx + 750 * (idx - 1), int((2479 - height) / 2)))
        idx += 1
        if idx == 5:
            idx = 1
            bg.save(f"{file_name()}-{i}.png")
            bg = Image.new('RGB', (3508, 2479), (255, 255, 255))

    bg.save(f"{file_name()}-{idx}.png")


if __name__ == '__main__':
    join_image()
